﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;


namespace Coletor
{
    public class Coletor
    {
        public int Matricula { get; set; }
        public int Mes { get; set; }
        public int Ano { get; set; }

        public string Coletar(String matricula, int Mes, int Ano)
        {
            String conteudoDoPost = string.Format("dados[empresa]=a665612&dados[matricula]={0}&dados[senha]={0}",matricula);
            String request = "http://www.ahgora.com.br/batidas/entrar/ajax";
            String batidas = string.Format("http://www.ahgora.com.br/batidas/ver/{0:00}-{0:0000}",Ano);

            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] data = encoding.GetBytes(conteudoDoPost);

            HttpWebRequest requisicao = (HttpWebRequest)WebRequest.Create("http://www.ahgora.com.br/batidas/entrar/ajax");
            requisicao.Method = "POST";
            requisicao.ContentType = "application/x-www-form-urlencoded";
            requisicao.Accept = "Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            requisicao.ContentLength = data.Length;

            using (Stream stream = requisicao.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }

            HttpWebResponse response = (HttpWebResponse)requisicao.GetResponse();
            string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

            return responseString;
        }
    }
}
